import 'package:get/get.dart';

import '../model/response.dart';
// import 'package:pull_to_refresh/pull_to_refresh.dart';
//
// import 'package:bms_ad/http/model/response.dart';
//
// extension RefreshStateExt on RefreshController {
//   void finishState(bool complete, [bool noData = false]) {
//     if (isRefresh) {
//       complete ? refreshCompleted() : refreshFailed();
//     }
//     if (isLoading) {
//       complete ? loadComplete() : loadFailed();
//     }
//     noData ? loadNoData() : resetNoData();
//   }
// }

typedef Success<T> = void Function(T? data);
typedef Failure = void Function(int code, String msg);
typedef FinalFunc = void Function(bool ok);

extension AppResponseExt<T> on AppResponse<T> {
  void doFunc(
      {required Success<T> success, Failure? failure, FinalFunc? finalFunc}) {
    if (ok) {
      var data = this.data;
      success.call(data);
    } else {
      failure?.call(code, msg);
    }
    finalFunc?.call(ok);
  }
}

extension StringLibExt on String {
  String transNet() {
    if (isNotEmpty && contains(RegExp(r'@'), 1)) {
      var buffer = StringBuffer();
      var sp = split(RegExp(r'@'));
      for (final element in sp) {
        buffer.write(element.tr);
      }
      return buffer.toString();
    }
    return tr;
  }
}
